package cn.liutao.dish.service;


import cn.liutao.common.utils.ServletUtils;
import cn.liutao.dish.entity.po.Taste;
import cn.liutao.dish.mapper.TasteMapper;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;

/**
 * 口味表 服务层实现。
 *
 * @author liutao
 * @since 2023-11-01
 */

public class TasteService{
    private static volatile TasteService instance;
    private TasteMapper tasteMapper;
    //私有构造方法
    private TasteService(){
        tasteMapper = ServletUtils.getMapper(TasteMapper.class);
    }

    /**
     * 双重检查锁实现单例
     * @return
     */
    public static TasteService getInstance(){
        if (instance==null){
            synchronized (TasteService.class){
                if (instance==null){
                    instance = new TasteService();
                }
            }
        }
        return instance;
    }

    public Page<Taste> selectByList(Taste queryParam) {
        QueryWrapper qw = QueryWrapper.create()
                .where(Taste::getName).like(queryParam.getName())
                .and(Taste::getStatus).eq(queryParam.getStatus())
                .and(Taste::getPrice).eq(queryParam.getPrice());
        Page<Taste> paginate = tasteMapper.paginate(queryParam.getPageNum(), queryParam.getPageSize(), qw);
        return paginate;
    }

    public void insert(Taste addParam) {
        tasteMapper.insertSelective(addParam);
    }

    public void updateById(Taste taste) {
        tasteMapper.update(taste);
    }

    public void deleteById(Integer id) {
        tasteMapper.deleteById(id);
    }
}
